﻿/*
{
"状态":1,
"名称":"新增-菜单资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"新增-菜单资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @menu_key char(32) , @father_menu char(32) , @menu_code varchar(100), @menu_name varchar(100),@order_index int
declare @menu_power_id varchar(100)
declare @port nvarchar(200)
declare @menu_id varchar(10)

set @menu_key = Lower(replace(NewID() ,'-',''))
set @father_menu ='{father_menu}' 
set @menu_code = '{menu_code}'
set @menu_name = '{menu_name}'
set @order_index = '{order_index}'
set @menu_power_id = '{menu_power_id}'
set @port='{port}'
set @menu_id='{menu_id}'

--校验信息
if isnull(@menu_name,'')=''
begin 
	RAISERROR ('SQL:菜单名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@menu_code,'')=''
begin 
	RAISERROR ('SQL:菜单代码不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@order_index,'')=''
begin 
	RAISERROR ('SQL:菜单序号不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@menu_power_id,'')=''
begin 
	RAISERROR ('SQL:菜单需求权限id不允许为空', 16 ,1 ) ; 
	return 
end 

 
if not Exists(select 1 from y_power where power_id=@menu_power_id)
begin
	RAISERROR ('SQL:菜单需求权限id不存在,请检查', 16 ,1 ) ; 
	return
end 

if isnull(@menu_id,'')<>'' and  Exists(select 1 from y_menu where menu_id=@menu_id and port=@port)
begin
	RAISERROR ('SQL:菜单id已经存在,请检查', 16 ,1 ) ; 
	return
end 

INSERT INTO [dbo].y_menu([menu_key],[father_menu],[menu_code],[menu_name],[icon],[port],[route_url],[order_index],[menu_power_id],[create_time],[update_time],[menu_id])
VALUES( @menu_key  , @father_menu , @menu_code , @menu_name , 'edit' , @port , '',@order_index ,@menu_power_id, getdate() , getdate(),@menu_id )